package dk.aiszone.lang.messer.autosource;

import dk.aiszone.lang.autosource.generatorobjects.Class;
import dk.aiszone.lang.autosource.generatorobjects.interfaces.GeneratorObject;
import dk.aiszone.lang.autosource.generatorobjects.interfaces.SimpleBlockObject;
import dk.aiszone.lang.messer.autosource.interfaces.AbstractModifiableObject;

/**
 * Representation of the return-statement.
 * 
 * @author Ais
 */
public class ReturnStatement extends AbstractModifiableObject implements SimpleBlockObject {

    private SimpleBlockObject modifiedObject;
    private final SimpleBlockObject object;
    private final Class type;

    /**
     * Constructor for the <code>ReturnStatement</code> object.
     * 
     * @param object
     *            The thing being returned.
     * @param type
     *            <code>Class</code> representing the
     * @param row
     *            The line of the <code>ModifialbleStatement</code>.
     * @param column
     *            The column of the <code>ModifiableStatement</code>.
     */
    public ReturnStatement(SimpleBlockObject object, Class type, int row, int column) {
        super(row, column);
        this.object = object;
        this.type = type;
    }

    @Override
    public Object clone() {
        return new ReturnStatement((SimpleBlockObject)object.clone(), type, row, column);
    }

    @Override
    public void revert() {
        modifiedObject = null;
    }

    @Override
    public String toJava() {
        return "return " + object.toJava();
    }

    @Override
    public SimpleBlockObject getChild(int index) {
        if (index == 0) {
            return object;
        }
        throw new IndexOutOfBoundsException(index + " out of bounds");
    }

    @Override
    public int getChildCount() {
        return 1;
    }

    @Override
    public int getNumberOfSupportedModifications() {
        return (type.isPrimitive() ? 1 : 0);
    }

    @Override
    public void modify(int index) {

    }
}